﻿/*  ----------------------------------------------------------------------------
 *  ITGROUP
 *  ----------------------------------------------------------------------------
 *  IBBA Infra Web
 *  ----------------------------------------------------------------------------
 *  File:       BreadCrumbUserControl.ascx.cs
 *  Author:     ITGROUP\eduardog
 *  ----------------------------------------------------------------------------
 */
using System;
using System.Web;
using bba.framework.infraweb.baseinfra.controller;
using bba.framework.infraweb.interfaces.controller;

namespace ibba.src.noriskbo.Web.Controls
{
    /// <summary>
    /// Classe reponsável pelo(s) controle(s) do BreadCrumb na MasterPage
    /// </summary>
    public partial class BreadCrumb : System.Web.UI.UserControl
    {

        #region Fields
        /// <summary>
        /// Campo utilizado para armazenar temporariamente a Id da feature (módulo) corrente 
        /// </summary>
        public int featureId;

        /// <summary>
        /// Campo utilizado para armazenar temporariamente a Id do sistema corrente
        /// </summary>
        public int sistemaId;

        /// <summary>
        /// Campo utilizado para armazenar temporariamente a Id da feature (opção) corrente
        /// </summary>
        public int featureIdChild;
        #endregion

        #region Events
        /// <summary>
        /// Evento acionado ao carregar este web user control. Todo o objeto <see cref="HttpResponse"/> é montado neste evento.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["featChidId"] == null)
            {
                LoadControlController(sistemaId, featureId, featureIdChild);
                if (featureIdChild != 0)
                    SaveSessionControl();
            }
            else
            {
                if (featureIdChild == 0)
                {
                    if (sistemaId == 0)
                        LoadControlController(Convert.ToInt32(Session["systemId"]), Convert.ToInt32(Session["featId"]), Convert.ToInt32(Session["featChidId"]));
                    else
                    {
                        LoadControlController(sistemaId, featureId, Convert.ToInt32(Session["featChidId"]));
                        SaveSessionControl();
                    }
                }
                else
                {
                    LoadControlController(sistemaId, featureId, Convert.ToInt32(Session["featChidId"]));
                    SaveSessionControl();
                }
            }
        }

        private void LoadControlController(int systemId, int feat, int featchild)
        {
            IBreadcrumbControlController controller = new BreadcrumbControlController();
            controller.load(systemId, feat, featchild, lblBreadCrumb);
        }

        private void SaveSessionControl()
        {
            Session.Add("systemId", sistemaId);
            Session.Add("featId", featureId);
            Session.Add("featChidId", featureIdChild);
        }

        #endregion


    }
}
